home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / networking / misc / wu-ftpd-37.14.lha / wu-ftpd / src / unixdirs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-30  |  1.4 KB  |  91 lines

  1. /*
  2.  * Routine to convert a UNIX-style path to an AmigaDOS path.
  3.  * 
  4.  * Based on routine by Martin W. Scott (from UnixDirs II).
  5.  * Major cleanup and bugfixing for use in wu-ftpd by Blaz Zupan, 07/94
  6.  */
  7.  
  8. #include <string.h>
  9.  
  10. /*
  11.  * "path" is a pointer to the Unix path to be
  12.  * converted. The result is put back into "path"
  13.  * because it is never longer than the original path.
  14.  */
  15. void
  16. UnixToAmiga (char *path)
  17. {
  18.   char *s, *t, *start;
  19.  
  20.   s = path;
  21.   start = path;
  22.  
  23.   if (t = strchr (path, ':'))    /* check for ':' in path */
  24.   {
  25.     t++;            /* copy device component */
  26.     while (path < t)
  27.       *s++ = *path++;
  28.   }
  29.  
  30.   while (path[0])
  31.   {
  32.     if ((path == start || path[-1] == '/') && path[0] == '.')
  33.     {
  34.       if (path[1] == '.')
  35.       {
  36.     if (path[2] == '/')
  37.     {
  38.       path += 2;
  39.       *s++ = *path++;
  40.     }
  41.     else if (!path[2])
  42.     {
  43.       path += 2;
  44.       *s++ = '/';
  45.     }
  46.     else
  47.       *s++ = *path++;
  48.       }
  49.       else
  50.       {
  51.     if (path[1] == '/')
  52.       path += 2;
  53.     else if (!path[1])
  54.       path += 1;
  55.     else
  56.       *s++ = *path++;
  57.       }
  58.     }
  59.     else
  60.       *s++ = *path++;
  61.   }
  62.   *s = '\0';
  63. }
  64.  
  65. #ifdef TEST
  66.  
  67. #include <proto/exec.h>
  68. #include <stdio.h>
  69.  
  70. int
  71. main (int argc, char **argv)
  72. {
  73.   int i;
  74.  
  75.   for (i = 1; i < argc; i++)
  76.   {
  77.     char *buf;
  78.  
  79.     if (buf = AllocMem (512, 0))
  80.     {
  81.       CopyMem (argv[i], buf, 512);
  82.       UnixToAmiga (buf);
  83.       printf ("%s --> %s\n", argv[i], buf);
  84.       FreeMem (buf, 512);
  85.     }
  86.   }
  87.   return 0;
  88. }
  89.  
  90. #endif
  91.